{extend name="public:base"}
{block name="body"}
<style>
    .layui-form-pane .layui-form-label {width: 200px;}
    .layui-form-pane .layui-input-block{margin-left: 200px;}
</style>
<body class="pear-container">
	<form class="layui-form layui-form-pane" action="">
		<div class="layui-card">
            <div class="layui-card-body">	
            {volist name="list" id="vo"}    
                {eq name="vo.type" value="string"}       
                <div class="layui-form-item">
                    <label class="layui-form-label">{$vo.title}</label>
                    <div class="layui-input-block">
                        <input type="text" name="{$vo.name}" value="{$vo.value|default=''}" lay-verify="required" autocomplete="off"
                            placeholder="{$vo.tips|default='请输入内容'}" class="layui-input">
                    </div>
                </div>
                {/eq}
                {eq name="vo.type" value="image"}
                <div class="layui-form-item">
                    <label class="layui-form-label">{$vo.title}</label>
                    <div class="layui-input-block" style="left:5px;">
                         <button class="pear-btn pear-btn-primary thumbBtn" type="button">图片上传</button>
                        <div class="upload_img_list" >
                            <div class="img_list" id="upload_box_thumb">
                                <img src="{$vo.value|default='/assets/library/admin/images/no_img.png'}" style="width:150px;max-width:150px" />
                                <input type="hidden" name="{$vo.name}" value="{$vo.value|default=''}">
                            </div>
                            
                        </div>
                    </div>
                </div>
                {/eq}
                {eq name="vo.type" value="boolean"}
                <div class="layui-form-item">
                    <label class="layui-form-label">{$vo.title}</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="{$vo.name}" lay-skin="switch" value="1" lay-text="开启|关闭" {eq name="vo.value" value='1'}checked{/eq}>
                       
                    </div>
                </div>
                {/eq}
            {/volist} 
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button type="submit" class="pear-btn pear-btn-primary " lay-submit=""lay-filter="form-save"><i class="layui-icon layui-icon-ok"></i>提交</button>
                    </div>
                </div>
            </div>
        </div>
		</form>
	</body>
{/block}
{block name="script"}
<script>
    layui.use(['jquery','form','upload'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        upload =layui.upload;
        upload.render({
			elem: '.thumbBtn'
			, url: '{:url("ajax/upload")}'
			, done: function (res) {
				//如果上传失败
				if (res.code == 0) {
					return layer.msg('上传失败');
				}
				let image = this.item.closest('layui-input-block').find('.img_list');
				image.find('input').attr('value', res.data);		
				image.find('img').attr('src', res.data);
			}
		});
        form.on('submit(form-save)', function(data) {
            $.ajax({
                url: '{:url("edit")}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code == 1) {
                        layer.msg('操作成功', {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("table-list");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
{/block}
